<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>李宁体育管理系统</title>

    <link rel="shortcut icon" href="favicon.ico">
    <link href="<%=path%>/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="<%=path%>/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="<%=path%>/css/plugins/chosen/chosen.css" rel="stylesheet">

    <link href="<%=path%>/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="<%=path%>/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="<%=path%>/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"
          rel="stylesheet">
    <link href="<%=path%>/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/css/style.min862f.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t"  id="signupForm" on>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">运营者用户名：</label>
								 
                            <div class="col-sm-4">
                                <input id="userName" name="userName" class="form-control" type="text" value="" maxlength="32" placeholder="这里输入用户名" title="用户名">
                            </div>
                            <span id="error_userName" style="color: red">*</span>
                        </div>
                       <input id="mpId" name="mpId" class="form-control" type="hidden" value="${user.mpId }" >
                        <div class="form-group">
                            <label class="col-sm-2 control-label">运营者密码：</label>

                            <div class="col-sm-4">
                                <input id="userPwd" name="userPwd" class="form-control" type="password"  maxlength="32" placeholder="输入密码" title="密码">
                            </div>
                            <span id="error_userPwd" style="color: red">*</span>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">运营者手机号：</label>

                            <div class="col-sm-4">
                                <input id="mobile" name="mobile" class="form-control" type="number" value=""   maxlength="11" placeholder="这里输入手机号" >
                            </div>
                            <span id="error_mobile" style="color: red">*</span>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">运营者邮箱：</label>

                            <div class="col-sm-4">
                                <input id="email" name="email" class="form-control" type="email" value=""  maxlength="64" placeholder="这里输入邮箱" >
                            </div>
                            <span id="error_email" style="color: red">*</span>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">运营者真实姓名：</label>

                            <div class="col-sm-4">
                                <input id="realName" name="realName" class="form-control"  value=""  maxlength="64" placeholder="运营者真实姓名">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">运营者公司名称：</label>

                            <div class="col-sm-4">
                                <input id="companyName" name="companyName" class="form-control"  value=""  maxlength="64" placeholder="运营者公司名称" title="真实姓名">
                            </div>
                        </div>
                     		 <div class="form-group">
                            <label class="col-sm-2 control-label">角色：</label>

                            <div class="col-sm-4">
                                   <select class="chosen-select form-control" name="roleCode" id="roleCode" data-placeholder="请选择角色" >
                                <option value=""></option>
                                <c:forEach items="${list }" var="mp">
                                    <option value="${mp.id }" selected>${mp.roleName }</option>
                                </c:forEach>
                            </select>
                            </div>
                            <span id="error_roleCode" style="color: red">*</span>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">提交</button>
                                &nbsp;<button class="btn btn-info" type="button" onclick="goback()">返回</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="<%=path%>/js/jquery.min.js?v=2.1.4"></script>
<script src="<%=path%>/js/bootstrap.min.js"></script>
<script src="<%=path%>/js/jquery.validate.js"></script>
<script src="<%=path%>/js/jquery.serializeObject.js"></script>
<!--下拉框-->
<script src="<%=path%>/js/plugins/chosen/chosen.jquery.js"></script>

<script>
var config = {
        ".chosen-select": {},
        ".chosen-select-deselect": {allow_single_deselect: !0},
        ".chosen-select-no-single": {disable_search_threshold: 10},
        ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
        ".chosen-select-width": {width: "95%"}
    };
for (var selector in config)$(selector).chosen(config[selector]);
    $(document).ready(function () {
    	var flage=true;
    	$("#signupForm").validate({
    		rules: {
    			userName: {
    				required: true,
    			},
    			userPwd: {
    				required: true,
    			},
    			mobile: {
    				required: true,
    				rangelength:[11,11]
    			},
    			email: {
    				required: true,
    				email:true,
    			},
    			roleCode: {
    				required: true,
    			}

    		},
    		messages:{
    			userName:{
    				required: "用户名不能为空"
    			},
    			userPwd:{
    				required: "密码不能为空"
    			},
    			mobile:{
    				required: "电话号码不符合规则"
    			},
    			email:{
    				required: "邮箱不符合规则"
    			},
    			roleCode:{
    				required: "角色不能为空"
    			},
    		
    		},
    		errorPlacement: function(error, element) {
    			$( element ).closest( "form" ).find( "span[id='error_" + element.attr( "name" ) + "']" ).append( error );
    		},
    	    onkeyup: false,
    		submitHandler:function(){	
    			var roleForm = $("#signupForm").serializeObject();
    			if(flage){
    			jQuery.ajax({
    				type: "post",
    			    url: "<%=path%>/operator/toSaveOperator",
    			    contentType: "application/json",
    			    data: JSON.stringify(roleForm),
    			    beforeSend:function() {
    			    	$("#progress").modal();
    			    	$("#loading").html("正在提交用戶数据，请稍候...");

    			    },
    			    complete:function(data) {
    			    	$("#progress").modal('hide');
    			    	$("#loading").html("");
    			    }, 
    			    success: function (data) {
    			    	if(data.status==200){
    			    		parent.layer.msg("保存运营者数据信息成功!",{time: 500},function(){goback();});
    			    	}else{
    			    		parent.layer.msg("保存运营者数据信息失败!");			    		
    			    	}
    			    },
    			    error: function () {
    			    	parent.layer.msg("保存运营者数据信息失败,请联系管理员!");
    			    }	
    			});
    			}else{
    				$("#error_userName").html("用户名重复无法提交");
    			}
    		}
    	});
        $("#userName").blur(function(){
        	var userName=$("#userName").val();
        	$("#error_userName").html("");
        	if(userName){
        		jQuery.ajax({
    				type: "post",
    			    url: "<%=path%>/user/toCheckUserName",
    			    dateType: "json",
    			    data: {"userName":userName},
    			    success: function (data) {
    			    	if(data.status==400){
    			    		$("#error_userName").html(data.msg);
    			    		flage=false;
    			    	}else{
    			    		$("#error_userName").html("");
    			    		flage=true;
    			    	}
    			    },
    			});	
        	}
        });
    });
    

    
    function goback() {
    	window.location.href="<%=path%>/operator/listOpeartor";
	}
</script>
</body>
</html>
